package project.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import project.model.ARoom;
import project.model.Hero;
import project.model.Mecung;

public class Application {

    public static void main(String[] args) throws IOException {
    	String RAUMAUFBAU = "./src/project/resource/res_dateien/Raumaufbau_nr2.txt";
    	File file = new File(RAUMAUFBAU);
    	String ZAUBER = "./src/project/resource/res_zauber/Fragen.txt";
    	File fileDungeon = new File(ZAUBER);
    	
    	System.out.println(file.getCanonicalPath());
    	Mecung mecung = new Mecung(file);
    	mecung.duaGiaTriDungeonVao(fileDungeon);
    	
    	String[][] rooms = mecung.docFile(file);
    	mecung.roomsDuocDuaVao(rooms);
    	mecung.roomsLienKetVoiNhau(rooms);
    	mecung.toaDoNormal(rooms);
    	mecung.ganGiaTriToaDoRoom(rooms);
    	
    	ARoom aroom = mecung.getRoomTheoNumber(1);
    	Hero tom = new Hero("Hero", aroom);
    	//tom.addObserver(mecung);
    	mecung.heroLogin(tom);
    	aroom.setVisitor(tom);
    	
        ViewHelper view = new ViewHelper(mecung);
        view.buildView();
        
        JFrame frame = new JFrame("Adventure Game");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        addMenuBar(frame);
        frame.add(view);
        
        frame.pack();
        frame.setVisible(true);
    }

	private static void addMenuBar(JFrame frame) {
		JMenuBar menuBar = new JMenuBar();
    	frame.setJMenuBar(menuBar);

    	JMenu fileMenu = new JMenu("File");
    	JMenu lookMenu = new JMenu("Look & Feel");
    	JMenu infoMenu = new JMenu("Info");
    	
    	JMenuItem raumaufbauAction    = new JMenuItem("File Raumaufbau");
    	JMenuItem magicQuestionAction = new JMenuItem("MagicQuestion");
    	JMenuItem avatarHeroAction    = new JMenuItem("Avatar Hero");
    	JMenuItem roomIconAction      = new JMenuItem("Room Icon");
    	JMenuItem magicRoomIconAction = new JMenuItem("Magic Room Icon");
    	JMenuItem helpAction          = new JMenuItem("Help");
    	JMenuItem authorAction        = new JMenuItem("Author");
    	
    	fileMenu.add(raumaufbauAction);
    	fileMenu.add(magicQuestionAction);
    	lookMenu.add(avatarHeroAction);
    	lookMenu.add(roomIconAction);
    	lookMenu.add(magicRoomIconAction);
    	infoMenu.add(helpAction);
    	infoMenu.add(authorAction);
    	
    	menuBar.add(fileMenu);
    	menuBar.add(lookMenu);
    	menuBar.add(infoMenu);
    	
    	raumaufbauAction.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				JFileChooser saveFile = new JFileChooser();
                int returnVal = saveFile.showSaveDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    String path = saveFile.getSelectedFile().getAbsolutePath();
                    File file = new File(path);
                }
			}
		});
    	
    	magicQuestionAction.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				JFileChooser saveFile = new JFileChooser();
                int returnVal = saveFile.showSaveDialog(null);
                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    String path = saveFile.getSelectedFile().getAbsolutePath();
                    File file = new File(path);
                }
			}
		});
    	
    	
	}

}
